package org.firebug.metadata.client.configuration;

import com.netflix.hystrix.exception.HystrixBadRequestException;
import feign.Util;
import feign.codec.ErrorDecoder;
import org.springframework.context.annotation.Bean;

import java.io.IOException;

public class FeignClientConfiguration {
    @Bean
    public ErrorDecoder errorDecoder() {
        return (methodKey, response) -> {
            String json = "";
            try {
                json = Util.toString(response.body().asReader());
            } catch (IOException e) {
                e.printStackTrace();
            }
            return new HystrixBadRequestException(json);
        };
    }
}